//
//  MainTabBar.m
//  iOS07-Weibo-LPK-OC
//
//  Created by 罗培克 on 6/28/15.
//  Copyright © 2015 lpk. All rights reserved.
//

#import "MainTabBar.h"

#define LPKSubItems 5
@interface MainTabBar()
/// 自定义 tabBarItem
@property (strong, nonatomic)UIButton *composeItem;

@end

@implementation MainTabBar

-(void)layoutSubviews {
    [super layoutSubviews];
    
    CGFloat w = self.bounds.size.width / LPKSubItems;
    CGRect rect = CGRectMake(0, 0, w, self.bounds.size.height);
    int i = 0;
    
    for (UIView *v in self.subviews) {
        if ([v isKindOfClass:[UIControl class]] && ![v isKindOfClass:[UIButton class]]) {
            v.frame = CGRectOffset(rect, w * i, 0);
            i += i == 1 ? 2 : 1;
        }
            
        self.composeItem.frame = CGRectOffset(rect, w * 2, 0);
    }
}

#pragma mark - 懒加载
-(UIButton *)composeItem {
    if (_composeItem == nil) {
        _composeItem = [UIButton buttonWithType:UIButtonTypeCustom];
        [_composeItem setImage:[UIImage imageNamed:@"tabbar_compose_icon_add"] forState:UIControlStateNormal];
        [_composeItem setImage:[UIImage imageNamed:@"tabbar_compose_icon_add_highlighted"] forState:UIControlStateHighlighted];
        [_composeItem setBackgroundImage:[UIImage imageNamed:@"tabbar_compose_button_highlighted"] forState:UIControlStateHighlighted];
        [_composeItem setBackgroundImage:[UIImage imageNamed:@"tabbar_compose_button"] forState:UIControlStateNormal];
        [self addSubview:_composeItem];
    }
    return _composeItem;
}

@end
